package masterjava.common.shared.state;

import org.jetbrains.annotations.Nullable;

import java.io.Serializable;

/**
 * User: GKislin
 * Date: May 26, 2010
 * <p/>
 * Base class for object with state
 */
public class State implements Serializable {

    private volatile String message;
    protected volatile Throwable exception;
    private volatile StateType stateType = StateType.OK;

    public void clearState() {
        message = null;
        stateType = StateType.OK;
        exception = null;
    }

    public void setState(StateType type, String msg, @Nullable Throwable e) {
        this.stateType = type;
        this.exception = e;
        this.message = msg;
    }

    public boolean isOk() {
        return stateType == StateType.OK;
    }

    public StateType getStateType() {
        return stateType;
    }

    public String getMessage() {
        return message;
    }

    public Throwable getException() {
        return exception;
    }
}
